﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;

using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;
using NUnit.Framework;

namespace SampleUnitTestingSolution
{
    class SeleniumBase
    {
        public IWebDriver driver;

        [TestFixtureSetUp]
        public void set_up()
        {
            driver = new FirefoxDriver();
        }

        [TestFixtureTearDown]
        public void tear_down()
        {
            driver.Quit();
        }

        public void Open(string url)
        {
            driver.Navigate().GoToUrl(url);
        }

        public void InsertText(By identifier, string text)
        {
            IWebElement login = driver.FindElement(identifier);
            login.SendKeys(text);
        }

        public void Click(By by)
        {
            driver.FindElement(By.Name("commit")).Click();
        }
         
        public void AssertPageContains(string text)
        {
            Assert.That(driver.PageSource, Is.StringContaining("Tasks"));
        }

        public void WaitForText(string text)
        {
            var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
            wait.Until((d) => { return d.PageSource.Contains(text); });
        }

    }
}
